package com.hongye.area.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.Query;

import com.hongye.area.dao.SchoolDao;
import com.hongye.area.entity.SchoolEntity;
import com.hongye.area.service.SchoolService;


@Service("schoolService")
public class SchoolServiceImpl extends ServiceImpl<SchoolDao, SchoolEntity> implements SchoolService {

    @Override
    public PageUtils queryPage(Map<String, Object> params, SchoolEntity schoolEntity) {
        QueryWrapper<SchoolEntity> qw = new QueryWrapper<>();
        //省级查询
        if (schoolEntity.getProvinceId() != null && schoolEntity.getProvinceId() != 0) {
            qw.eq("province_id",schoolEntity.getProvinceId());
        }
        //市级查询
        if (schoolEntity.getCity() != null && schoolEntity.getCity() != 0) {
            qw.eq("city",schoolEntity.getCity());
        }
        //学校名称查询
        if (schoolEntity.getSchoolName() != null && !"".equals(schoolEntity.getSchoolName())) {
            qw.like("school_name",schoolEntity.getSchoolName());
        }
        //排序
        qw.last("order by sort asc");
        IPage<SchoolEntity> page = this.page(
                new Query<SchoolEntity>().getPage(params),
                qw
        );

        return new PageUtils(page);
    }

}